home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
program
/
gcc
/
gcc270-d.lha
/
gnu
/
man
/
cat3
/
glob.0
< prev
next >
Wrap
Text File
|
1992-08-10
|
10KB
|
199 lines
GLOB(3) UNIX Programmer's Manual GLOB(3)
NNAAMMEE
gglloobb, gglloobbffrreeee - generate pathnames matching a pattern
SSYYNNOOPPSSIISS
##iinncclluuddee <<gglloobb..hh>>
_i_n_t
gglloobb(_c_o_n_s_t _c_h_a_r _*_p_a_t_t_e_r_n, _i_n_t _f_l_a_g_s, _c_o_n_s_t _i_n_t _(_*_e_r_r_f_u_n_c_)_(_c_h_a_r _*_, _i_n_t_),
_g_l_o_b___t _*_p_g_l_o_b)
_v_o_i_d
gglloobbffrreeee(_g_l_o_b___t _*_p_g_l_o_b)
DDEESSCCRRIIPPTTIIOONN
The gglloobb() function is a pathname generator that implements the rules for
file name pattern matching used by the shell.
The include file _g_l_o_b_._h defines the structure type _g_l_o_b___t, which contains
at least the following fields:
typedef struct {
int gl_pathc; /* count of total paths so far */
int gl_matchc; /* count of paths matching pattern */
int gl_offs; /* reserved at beginning of gl_pathv */
int gl_flags; /* returned flags */
char **gl_pathv; /* list of paths matching pattern */
} glob_t;
The argument _p_a_t_t_e_r_n is a pointer to a pathname pattern to be expanded.
The gglloobb() argument matches all accessible pathnames against the pattern
and creates a list of the pathnames that match. In order to have access
to a pathname, gglloobb() requires search permission on every component of a
path except the last and read permission on each directory of any file
name component of _p_a_t_t_e_r_n that contains any of the special characters
`*', `?' or `['.
The gglloobb() argument stores the number of matched pathnames into the
_g_l___p_a_t_h_c field, and a pointer to a list of pointers to pathnames into the
_g_l___p_a_t_h_v field. The first pointer after the last pathname is NULL. If
the pattern does not match any pathnames, the returned number of matched
paths is set to zero.
It is the caller's responsibility to create the structure pointed to by
_p_g_l_o_b. The gglloobb() function allocates other space as needed, including the
memory pointed to by _g_l___p_a_t_h_v.
The argument _f_l_a_g_s is used to modify the behavior of gglloobb(). The value
of _f_l_a_g_s is the bitwise inclusive OR of any of the following values de
fined in _g_l_o_b_._h:
GLOB_APPEND Append pathnames generated to the ones from a previous call
(or calls) to gglloobb(). The value of _g_l___p_a_t_h_c will be the
total matches found by this call and the previous call(s).
The pathnames are appended to, not merged with the path
names returned by the previous call(s). Between calls, the
caller must not change the setting of the GLOB_DOOFFS flag,
nor change the value of _g_l___o_f_f_s when GLOB_DOOFFS is set,
nor (obviously) call gglloobbffrreeee() for _p_g_l_o_b.
GLOB_DOOFFS Make use of the _g_l___o_f_f_s field. If this flag is set,
_g_l___o_f_f_s is used to specify how many NULL pointers to
prepend to the beginning of the _g_l___p_a_t_h_v field. In other
words, _g_l___p_a_t_h_v will point to _g_l___o_f_f_s NULL pointers, fol
lowed by _g_l___p_a_t_h_c pathname pointers, followed by a NULL
pointer.
GLOB_ERR Causes gglloobb() to return when it encounters a directory that
it cannot open or read. Ordinarily, gglloobb() continues to
find matches.
GLOB_MARK Each pathname that is a directory that matches _p_a_t_t_e_r_n has
a slash appended.
GLOB_NOCHECK If _p_a_t_t_e_r_n does not match any pathname, then gglloobb() returns
a list consisting of only _p_a_t_t_e_r_n, with the number of total
pathnames is set to 1, and the number of matched pathnames
set to 0. If GLOB_QUOTE is set, its effect is present in
the pattern returned.
GLOB_NOMAGIC Is the same as GLOB_NOCHECK but it only appends the _p_a_t_t_e_r_n
if it does not contain any of the special characters ``*'',
``?'' or ``[''. GLOB_NOMAGIC is provided to simplify im
plementing the historic csh(1) globbing behavior and should
probably not be used anywhere else.
GLOB_NOSORT By default, the pathnames are sorted in ascending ASCII or
der; this flag prevents that sorting (speeding up gglloobb()).
GLOB_QUOTE Use the backslash (`\') character for quoting: every occur
rence of a backslash followed by a character in the pattern
is replaced by that character, avoiding any special inter
pretation of the character.
If, during the search, a directory is encountered that cannot be opened
or read and _e_r_r_f_u_n_c is nonNULL, gglloobb() calls _(_*_e_r_r_f_u_n_c_)_(_p_a_t_h_,_e_r_r_n_o_).
This may be unintuitive: a pattern like `*/Makefile' will try to stat(2)
`foo/Makefile' even if `foo' is not a directory, resulting in a call to
_e_r_r_f_u_n_c. The error routine can suppress this action by testing for ENOENT
and ENOTDIR; however, the GLOB_ERR flag will still cause an immediate re
turn when this happens.
If _e_r_r_f_u_n_c returns nonzero, gglloobb() stops the scan and returns GLOB_ABEND
after setting _g_l___p_a_t_h_c and _g_l___p_a_t_h_v to reflect any paths already matched.
This also happens if an error is encountered and GLOB_ERR is set in
_f_l_a_g_s, regardless of the return value of _e_r_r_f_u_n_c, if called. If GLOB_ERR
is not set and either _e_r_r_f_u_n_c is NULL or _e_r_r_f_u_n_c returns zero, the error
is ignored.
The gglloobbffrreeee() function frees any space associated with _p_g_l_o_b from a pre
vious call(s) to gglloobb().
RREETTUURRNN VVAALLUUEESS
On successful completion, gglloobb() returns zero. In addition the fields of
_p_g_l_o_b contain the values described below:
_g_l___p_a_t_h_c contains the total number of matched pathnames so far.
This includes other matches from previous invocations of
gglloobb() if GLOB_APPEND was specified.
_g_l___m_a_t_c_h_c contains the number of matched pathnames in the current in
vocation of gglloobb().
_g_l___f_l_a_g_s contains a copy of the _f_l_a_g_s parameter with the bit
GLOB_MAGCHAR set if _p_a_t_t_e_r_n contained any of the special
characters ``*'', ``?'' or ``['', cleared if not.
_g_l___p_a_t_h_v contains a pointer to a NULLterminated list of matched
pathnames. However, if _g_l___p_a_t_h_c is zero, the contents of
_g_l___p_a_t_h_v are undefined.
If gglloobb() terminates due to an error, it sets errno and returns one of
the following nonzero constants, which are defined in the include file
<_g_l_o_b_._h>:
GLOB_NOSPACE An attempt to allocate memory failed.
GLOB_ABEND The scan was stopped because an error was encountered and
either GLOB_ERR was set or _(_*_e_r_r_f_u_n_c_)_(_) returned nonzero.
The arguments _p_g_l_o_b_-_>_g_l___p_a_t_h_c and _p_g_l_o_b_-_>_g_l___p_a_t_h_v are still set as speci
fied above.
SSEEEE AALLSSOO
sh(1), fnmatch(3), wordexp(3), regexp(3)
SSTTAANNDDAARRDDSS
The gglloobb() function is expected to be IEEE Std1003.2 (``POSIX'') compati
ble with the exception that the flag GLOB_QUOTE and the fields _g_l___m_a_t_c_h_c
and _g_l___f_l_a_g_s should not be used by applications striving for strict POSIX
conformance.
EEXXAAMMPPLLEE
A rough equivalent of `ls l *.c *.h' can be obtained with the following
code:
GLOB_t g;
g.gl_offs = 2;
glob("*.c", GLOB_DOOFFS, NULL, &g);
glob("*.h", GLOB_DOOFFS | GLOB_APPEND, NULL, &g);
g.gl_pathv[0] = "ls";
g.gl_pathv[1] = "l";
execvp("ls", g.gl_pathv);
HHIISSTTOORRYY
The gglloobb() and gglloobbffrreeee() functions are currently under development.
BBUUGGSS
Patterns longer than MAXPATHLEN may cause unchecked errors.
The gglloobb() argument may fail and set errno for any of the errors speci
fied for the library routines stat(2), closedir(3), opendir(3),
readdir(3), malloc(3), and free(3).
BSD Experimental July 31, 1991 3